package cn.fl.project.service.impl;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.fl.base.lnkcomp.vo.BasePrjLnkCompVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.project.service.ILnkCompModService;
import cn.fl.project.transform.LnkCompModVOTransform;
import cn.fl.project.transform.PrjLnkCompVOTransform;
import cn.fl.project.vo.LnkCompModVO;
import cn.fl.project.vo.PrjLnkCompVO;

import fl.constant.facade.framework.constant.BusinessIdConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import fl.spl.base.lnkcomp.dto.BasePrjLnkCompDTO;
import fl.spl.facade.framework.annotation.FieldApply;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.lnkcomp.api.ILnkCompModApiService;
import fl.spl.facade.lnkcomp.api.ILnkCompModDtlApiService;
import fl.spl.facade.lnkcomp.api.IPrjLnkCompApiService;
import fl.spl.facade.lnkcomp.api.IPrjLnkCompQueryApiService;
import fl.spl.facade.lnkcomp.condition.LnkCompModDtlQC;
import fl.spl.facade.lnkcomp.condition.LnkCompModQC;
import fl.spl.facade.lnkcomp.constant.LnkCompConstant;
import fl.spl.facade.lnkcomp.constant.PrjLnkCompRelInfoConstant;
import fl.spl.facade.lnkcomp.dto.LnkCompModDTO;
import fl.spl.facade.lnkcomp.dto.LnkCompModDtlDTO;
import fl.spl.facade.lnkcomp.dto.PrjLnkCompDTO;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.Pager;


/**
 * @Description: 挂靠公司变更申请主表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class LnkCompModServiceImpl implements ILnkCompModService {

	/**
	 * 自定义 API 自行注入需要的API服务
	 */

	@Autowired
	private ILnkCompModApiService lnkCompModApiService ;
	
	@Autowired
	private IPrjLnkCompApiService prjLnkCompApiService ;
	
	@Autowired
	private IPrjLnkCompQueryApiService prjLnkCompQueryApiService ;
	
	@Autowired
	private ILnkCompModDtlApiService lnkCompModDtlApiService ;
	
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService ;

	@Override
	public LnkCompModVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.newWebLogger("获取挂靠公司变更主表数据详情,id为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0002, "获取对象主键不能为空!");
		}
		//TODO 业务逻辑
		LnkCompModDTO dto = lnkCompModApiService.selectById(id);
		return LnkCompModVOTransform.toVO(dto);
	}

	@Override
	public Long add(LnkCompModVO entity) throws BaseException{
		if(null == entity){
			throw new BaseException(BaseExceptionConstant.COMMON_0002,"新增对象不存在!");
		};
		//return this.lnkCompModApiService.add(LnkCompModVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return null;
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.COMMON_0002,"删除对象主键不能为空!");
		};
		//return this.lnkCompModApiService.removeLnkCompModDTOById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
	@Override
    public boolean removeByIds(List<Long> ids)throws BaseException{
		if(CollectionUtils.isEmpty(ids)){
			throw new BaseException(BaseExceptionConstant.COMMON_0002,"删除对象主键不能为空!");
		};
		return false;
    }

	@Override
	public boolean modify(LnkCompModVO entity) throws BaseException{
		if(null == entity){
			throw new BaseException(BaseExceptionConstant.COMMON_0002,"修改对象不能为空!");
		};
		return this.lnkCompModApiService.modify(LnkCompModVOTransform.toDTO(entity));
		//TODO 业务逻辑
		//return false;
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page){
			page = new Pager();
		}
		//return this.lnkCompModApiService.searchLnkCompModListPage(page);
		//TODO 业务逻辑
		return null;
	}

	@Override
	public Long addLnkCompMod(LnkCompModDTO lnkCompModDTO, PrjLnkCompDTO prjLnkCompDTO, String sysCd, String orgCd)
			throws BaseException {
		// TODO Auto-generated method stub
		Long modId = this.lnkCompModApiService.addLnkCompMod(lnkCompModDTO, prjLnkCompDTO, sysCd, orgCd);
		this.saveLnkComp(prjLnkCompDTO);
		return modId;
	}

	@Override
	public boolean modifyBscAgain(PrjLnkCompDTO entity, Long modId, String sysCd, String orgCd) throws BaseException {
		// TODO Auto-generated method stub
		boolean b = this.lnkCompModApiService.modifyBscAgain(entity, modId, sysCd, orgCd, CurrentThreadContext.getCurrentUserId(), CurrentThreadContext.getCurrentUserName());
		this.saveLnkComp(entity);
		return b;
	}

	@Override
	public boolean modifyLnkCompModDtlFileList(Long lnkCompId, Long modId) throws BaseException {
		// TODO Auto-generated method stub
		return this.lnkCompModApiService.modifyLnkCompModDtlFileList(lnkCompId, modId);
	}
	
	private void saveLnkComp(PrjLnkCompDTO lnkCompDTO){
		// TODO Auto-generated method stub
		if(null == lnkCompDTO || StringUtils.isEmpty(lnkCompDTO.getId())){
			BaseLogUtils.newWebLogger("修改挂靠信息失败,对象参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0002, BaseExceptionConstant.COMMON_0002_NAME);
		}
		PrjLnkCompDTO dto = this.prjLnkCompQueryApiService.selectPrjLnkCompById(lnkCompDTO.getId());
		if(null == dto){
			BaseLogUtils.newWebLogger("修改挂靠信息失败,对象不存在!").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setKeys("ID", lnkCompDTO.getId().toString())
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0002, BaseExceptionConstant.COMMON_0002_NAME);
		}
		Field[] fields = BasePrjLnkCompDTO.class.getDeclaredFields();
		for (Field field : fields) {
			FieldApply fieldApply = field.getAnnotation(FieldApply.class);
			if (fieldApply == null || !fieldApply.isApplySign()){
				continue;
			}else{
				String fieldNm = fieldApply.fieldNm();
				// 字符串首字母大写
				char[] cs = fieldNm.toCharArray();
				cs[0] -= 32;
				// 调用get方法
				try {
					Field fieldSet = BasePrjLnkCompDTO.class.getDeclaredField(fieldNm);
					fieldSet.setAccessible(true);
					try {
						fieldSet.set(lnkCompDTO, null);
					} catch (IllegalArgumentException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IllegalAccessException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				} catch (NoSuchFieldException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SecurityException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		lnkCompDTO.setRlPsnList(null);
		this.prjLnkCompApiService.modifyPrjLnkComp(lnkCompDTO, CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd());
	
	}

	@Override
	public List<JSONObject> searchChangeList(Long lnkCompId) throws BaseException {
		
		List<JSONObject> resultList = new ArrayList<>();
		// TODO Auto-generated method stub
		PrjLnkCompDTO dto = this.prjLnkCompQueryApiService.selectPrjLnkCompByIdAndBuOrgCd(lnkCompId, CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd());
		PrjLnkCompVO vo = PrjLnkCompVOTransform.toVO(dto);
		if(CollectionUtils.isNotEmpty(dto.getSuppPrjTypCdList())){
			StringBuffer sb = new StringBuffer() ;
			List<String> suppPrjTypCdList = dto.getSuppPrjTypCdList();
			for (int i = 0; i < suppPrjTypCdList.size(); i++) {
				sb.append(suppPrjTypCdList.get(i));
				sb.append(";");
			}
			vo.setSuppPrjTypCd(sb.substring(0,sb.length()-1).toString());
		}
		LnkCompModQC qc = new LnkCompModQC();
		qc.setLnkCompId(lnkCompId);
		qc.setIsDel(BaseConstant.IS_YESNO_NO);
		qc.setIsValid(BaseConstant.IS_YESNO_YES);
		List<LnkCompModDTO> searchList = this.lnkCompModApiService.searchList(qc);
		if(CollectionUtils.isNotEmpty(searchList)){
			LnkCompModDtlQC lnkCompModDtlQC;
			for (LnkCompModDTO lnkCompModDTO : searchList) {
				lnkCompModDtlQC = new LnkCompModDtlQC();
				lnkCompModDtlQC.setIsDel(BaseConstant.IS_YESNO_NO);
				lnkCompModDtlQC.setIsValid(BaseConstant.IS_YESNO_YES);
				lnkCompModDtlQC.setModId(lnkCompModDTO.getId());
				List<LnkCompModDtlDTO> lnkCompModDtls = this.lnkCompModDtlApiService.searchList(lnkCompModDtlQC);
				JSONObject obj = new JSONObject();
				obj.put("id", lnkCompModDTO.getId());
				obj.put("prjLnkCompId", lnkCompModDTO.getLnkCompId());
				
				PrjLnkCompVO befVO = this.getPrjLnkCompVO(vo, lnkCompModDtls, "bef");
				obj.put("befLnkCompNm", befVO.getLnkCompNm());
				if(null != befVO.getRegDt()){
					obj.put("befRegDt", DateUtils.formatDateToString(befVO.getRegDt(), DateUtils.YYYY_MM_DD));
				}else{
					obj.put("befRegDt", befVO.getRegDt());
				}
				obj.put("befRegAddr", befVO.getRegAddr());
				obj.put("befCompTyp", befVO.getCompTyp());
				obj.put("befBizScope", befVO.getBizScope());
				obj.put("befSuppPrjTypCd", befVO.getSuppPrjTypCd());
				obj.put("befSucc", befVO.getSucc());
				
				PrjLnkCompVO aftVO = this.getPrjLnkCompVO(vo, lnkCompModDtls, "aft");
				obj.put("aftLnkCompNm", aftVO.getLnkCompNm());
				if(null != befVO.getRegDt()){
					obj.put("aftRegDt", DateUtils.formatDateToString(aftVO.getRegDt(), DateUtils.YYYY_MM_DD));
				}else{
					obj.put("aftRegDt", aftVO.getRegDt());
				}
				//obj.put("aftRegDt", aftVO.getRegDt());
				obj.put("aftRegAddr", aftVO.getRegAddr());
				obj.put("aftCompTyp", aftVO.getCompTyp());
				obj.put("aftBizScope", aftVO.getBizScope());
				obj.put("aftSuppPrjTypCd", aftVO.getSuppPrjTypCd());
				obj.put("aftSucc", aftVO.getSucc());
				obj.put("crtTm", DateUtils.formatDateToString(lnkCompModDTO.getCrtTm(), DateUtils.YYYY_MM_DDHHMMSS));
				resultList.add(obj);
			}
		}
		return resultList;
	}
	
	private PrjLnkCompVO getPrjLnkCompVO(PrjLnkCompVO compVO ,List<LnkCompModDtlDTO> modDtlDTOs, String type) throws BaseException{
		PrjLnkCompVO vo = compVO ;
		BaseLogUtils.newWebLogger("查询变更明细表记录").setLogOperType(LogOperEnum.REQ)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
				.setWarning(false)
				.setKeys("modDtlDTOs", JSON.toJSONString(modDtlDTOs))
				.info();
		for (LnkCompModDtlDTO lnkCompModDtlDTO : modDtlDTOs) {
			if("aft".equals(type)){
				if(lnkCompModDtlDTO.getModAttrFiled().equals("suppPrjTypCd")){
					vo.setSuppPrjTypCd(lnkCompModDtlDTO.getModConAft() );
				}else if(lnkCompModDtlDTO.getModAttrFiled().equals("regDt")){
					if(StringUtils.isNotEmpty(lnkCompModDtlDTO.getModConAft()) && !"null".equals(lnkCompModDtlDTO.getModConAft())){
						vo.setRegDtStr(lnkCompModDtlDTO.getModConAft());
						vo.setRegDt(DateUtils.formatDate(new Date(lnkCompModDtlDTO.getModConAft()), DateUtils.YYYY_MM_DD));
					}else{
						vo.setRegDt(null);
						vo.setRegDtStr(null);
					}
				}else if(lnkCompModDtlDTO.getModAttrFiled().equals("expDt")){
					if(StringUtils.isNotEmpty(lnkCompModDtlDTO.getModConAft()) && !"null".equals(lnkCompModDtlDTO.getModConAft())){
						vo.setExpDt(DateUtils.formatDate(new Date(lnkCompModDtlDTO.getModConAft()), DateUtils.YYYY_MM_DD));
						vo.setExpDtStr(lnkCompModDtlDTO.getModConAft());
					}else{
						vo.setExpDt(null);
						vo.setExpDtStr(null);
					}
				}else if(lnkCompModDtlDTO.getModAttrFiled().equals("isUploadLoa")){
					if(StringUtils.isNotEmpty(lnkCompModDtlDTO.getModConAft())){
						vo.setIsUploadLoa(Integer.valueOf(lnkCompModDtlDTO.getModConAft()));
					}
				}else if(lnkCompModDtlDTO.getModAttrFiled().equals("isRecycleLoa")){
					if(StringUtils.isNotEmpty(lnkCompModDtlDTO.getModConAft())){
						vo.setIsRecycleLoa(Integer.valueOf(lnkCompModDtlDTO.getModConAft()));
					}
				}else{
					if (lnkCompModDtlDTO.getTabNm().equals(LnkCompConstant.LNK_COMP_FLOW_S_H_LNK_TAB)) {
						Field field = null;
						try {
							BaseLogUtils.newWebLogger("获取field").setLogOperType(LogOperEnum.REQ)
									.setSysCd(CurrentThreadContext.getCurrentSysCd())
									.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
									.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
									.setWarning(false)
									.info();
							field = BasePrjLnkCompVO.class.getDeclaredField(lnkCompModDtlDTO.getModAttrFiled());
						} catch (NoSuchFieldException e) {
							e.printStackTrace();
						}
						field.setAccessible(true);
						try {
							BaseLogUtils.newWebLogger("写入值").setLogOperType(LogOperEnum.REQ)
									.setSysCd(CurrentThreadContext.getCurrentSysCd())
									.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
									.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
									.setWarning(false)
									.info();
							if(!"null".equals(lnkCompModDtlDTO.getModConAft())){
								field.set((Object) vo, lnkCompModDtlDTO.getModConAft());
							}
						} catch (IllegalAccessException e) {
							e.printStackTrace();
						}
					}
				}
			}else{
				if(lnkCompModDtlDTO.getModAttrFiled().equals("suppPrjTypCd")){
					vo.setSuppPrjTypCd(lnkCompModDtlDTO.getModConBef());
				}else if(lnkCompModDtlDTO.getModAttrFiled().equals("regDt")){
					if(StringUtils.isNotEmpty(lnkCompModDtlDTO.getModConBef()) && !"null".equals(lnkCompModDtlDTO.getModConBef())){
						//vo.setRegDt(DateUtils.formatStringToDate(lnkCompModDtlDTO.getModConAft(), DateUtils.YYYY_MM_DD));
						vo.setRegDtStr(lnkCompModDtlDTO.getModConBef());
						vo.setRegDt(DateUtils.formatStringToDate(lnkCompModDtlDTO.getModConBef(), DateUtils.YYYY_MM_DD));
					}else{
						vo.setRegDt(null);
						vo.setRegDtStr(null);
					}
				}else if(lnkCompModDtlDTO.getModAttrFiled().equals("expDt")){
					if(StringUtils.isNotEmpty(lnkCompModDtlDTO.getModConBef()) && !"null".equals(lnkCompModDtlDTO.getModConBef())){
						//vo.setRegDt(DateUtils.formatStringToDate(lnkCompModDtlDTO.getModConAft(), DateUtils.YYYY_MM_DD));
						vo.setExpDt(DateUtils.formatStringToDate(lnkCompModDtlDTO.getModConBef(), DateUtils.YYYY_MM_DD));
						vo.setExpDtStr(lnkCompModDtlDTO.getModConBef());
					}else{
						vo.setExpDt(null);
						vo.setExpDtStr(null);
					}
				}else{
					if (lnkCompModDtlDTO.getTabNm().equals(LnkCompConstant.LNK_COMP_FLOW_S_H_LNK_TAB)) {
						Field field = null;
						try {
							BaseLogUtils.newWebLogger("获取field").setLogOperType(LogOperEnum.REQ)
									.setSysCd(CurrentThreadContext.getCurrentSysCd())
									.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
									.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
									.setWarning(false)
									.info();
							field = BasePrjLnkCompVO.class.getDeclaredField(lnkCompModDtlDTO.getModAttrFiled());
						} catch (NoSuchFieldException e) {
							e.printStackTrace();
						}
						field.setAccessible(true);
						try {
							BaseLogUtils.newWebLogger("写入值").setLogOperType(LogOperEnum.REQ)
									.setSysCd(CurrentThreadContext.getCurrentSysCd())
									.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
									.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
									.setWarning(false)
									.info();
							if(!"null".equals(lnkCompModDtlDTO.getModConBef())){
								field.set((Object) vo, lnkCompModDtlDTO.getModConBef());
							}else{
								field.set((Object) vo, null);
							}
						} catch (IllegalAccessException e) {
							e.printStackTrace();
						}
					}
				}
			
			}
		}
	
		return vo ;
	}

	@Override
	public JSONObject searchModDtlByModId(Long modId,Long lnkCompId) throws BaseException {
		
		Map<String, String> map = this.sysDictionaryApiService.searchGroupToMap(SplSystemConstant.SPL_SYS_CD,
				SplSystemConstant.DEFAULT_ORG_CD, PrjLnkCompRelInfoConstant.SUPP_LNK_PRJ_TYP_DIC_CODE);
		
		StringBuffer sb ;
		
		PrjLnkCompDTO dto = this.prjLnkCompQueryApiService.selectPrjLnkCompByIdAndBuOrgCd(lnkCompId, CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd());
		PrjLnkCompVO vo = PrjLnkCompVOTransform.toVO(dto);
		// TODO Auto-generated method stub
		LnkCompModDtlQC lnkCompModDtlQC = new LnkCompModDtlQC();
		lnkCompModDtlQC.setIsDel(BaseConstant.IS_YESNO_NO);
		lnkCompModDtlQC.setIsValid(BaseConstant.IS_YESNO_YES);
		lnkCompModDtlQC.setModId(modId);
		List<LnkCompModDtlDTO> lnkCompModDtls = this.lnkCompModDtlApiService.searchList(lnkCompModDtlQC);
		JSONObject obj = new JSONObject();
		obj.put("id", modId);
		obj.put("prjLnkCompId", lnkCompId);
		PrjLnkCompVO befVO = this.getPrjLnkCompVO(vo, lnkCompModDtls, "bef");
		obj.put("befLnkCompNm", befVO.getLnkCompNm());
		obj.put("befRegDt", befVO.getRegDt());
		obj.put("befRegAddr", befVO.getRegAddr());
		obj.put("befCompTyp", befVO.getCompTyp());
		obj.put("befBizScope", befVO.getBizScope());
		
		if(StringUtils.isNotEmpty(befVO.getSuppPrjTypCd())){
			sb = new StringBuffer();
			String[] split = befVO.getSuppPrjTypCd().split(";");
			for (String string : split) {
				sb.append(map.get(string));
				sb.append(",");
			}
			obj.put("befSuppPrjTypCd", sb.substring(0, sb.length()-1).toString());
		}
		obj.put("befSucc", befVO.getSucc());
		obj.put("befExpDt", befVO.getExpDt());
		
		PrjLnkCompVO aftVO = this.getPrjLnkCompVO(vo, lnkCompModDtls, "aft");
		obj.put("aftLnkCompNm", aftVO.getLnkCompNm());
		obj.put("aftRegDt", aftVO.getRegDt());
		obj.put("aftRegAddr", aftVO.getRegAddr());
		obj.put("aftCompTyp", aftVO.getCompTyp());
		obj.put("aftBizScope", aftVO.getBizScope());
		if(StringUtils.isNotEmpty(aftVO.getSuppPrjTypCd())){
			sb = new StringBuffer();
			String[] split = aftVO.getSuppPrjTypCd().split(";");
			for (String string : split) {
				sb.append(map.get(string));
				sb.append(",");
			}
			obj.put("aftSuppPrjTypCd", sb.substring(0, sb.length()-1).toString());
		}
		//obj.put("aftSuppPrjTypCd", aftVO.getSuppPrjTypCd());
		obj.put("aftSucc", aftVO.getSucc());
		obj.put("aftExpDt", aftVO.getExpDt());
	
		return obj;
	}

	@Override
	public Pager searchChangeListPage(Pager page) throws BaseException {
		
		List<JSONObject> resultList = new ArrayList<>();
		// TODO Auto-generated method stub
		/*LnkCompModQC qc = new LnkCompModQC();
		qc.setLnkCompId(lnkCompId);
		qc.setIsDel(BaseConstant.IS_YESNO_NO);
		qc.setIsValid(BaseConstant.IS_YESNO_YES);*/
		Pager pager = this.lnkCompModApiService.searchListPage(page);
		List<LnkCompModDTO> searchList = (List<LnkCompModDTO>)pager.getResultList();
		if(CollectionUtils.isNotEmpty(searchList)){
			LnkCompModDtlQC lnkCompModDtlQC;
			for (LnkCompModDTO lnkCompModDTO : searchList) {
				PrjLnkCompDTO dto = this.prjLnkCompQueryApiService.selectPrjLnkCompByIdAndBuOrgCd(lnkCompModDTO.getLnkCompId(), CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd());
				PrjLnkCompVO vo = PrjLnkCompVOTransform.toVO(dto);
				if(CollectionUtils.isNotEmpty(dto.getSuppPrjTypCdList())){
					StringBuffer sb = new StringBuffer() ;
					List<String> suppPrjTypCdList = dto.getSuppPrjTypCdList();
					for (int i = 0; i < suppPrjTypCdList.size(); i++) {
						sb.append(suppPrjTypCdList.get(i));
						sb.append(";");
					}
					vo.setSuppPrjTypCd(sb.substring(0,sb.length()-1).toString());
				}
				lnkCompModDtlQC = new LnkCompModDtlQC();
				lnkCompModDtlQC.setIsDel(BaseConstant.IS_YESNO_NO);
				lnkCompModDtlQC.setIsValid(BaseConstant.IS_YESNO_YES);
				lnkCompModDtlQC.setModId(lnkCompModDTO.getId());
				List<LnkCompModDtlDTO> lnkCompModDtls = this.lnkCompModDtlApiService.searchList(lnkCompModDtlQC);
				JSONObject obj = new JSONObject();
				obj.put("dataId", lnkCompModDTO.getId());
				obj.put("prjLnkCompId", lnkCompModDTO.getLnkCompId());
				
				PrjLnkCompVO befVO = this.getPrjLnkCompVO(vo, lnkCompModDtls, "bef");
				obj.put("dataName", befVO.getLnkCompNm());
				if(null != befVO.getRegDt()){
					obj.put("befRegDt", DateUtils.formatDateToString(befVO.getRegDt(), DateUtils.YYYY_MM_DD));
				}else{
					obj.put("befRegDt", befVO.getRegDt());
				}
				obj.put("befRegAddr", befVO.getRegAddr());
				obj.put("attrCdNm", befVO.getCompTyp());
				obj.put("befBizScope", befVO.getBizScope());
				obj.put("befSuppPrjTypCd", befVO.getSuppPrjTypCd());
				obj.put("succ", befVO.getSucc());
				
				PrjLnkCompVO aftVO = this.getPrjLnkCompVO(vo, lnkCompModDtls, "aft");
				obj.put("aftLnkCompNm", aftVO.getLnkCompNm());
				if(null != befVO.getRegDt()){
					obj.put("aftRegDt", DateUtils.formatDateToString(aftVO.getRegDt(), DateUtils.YYYY_MM_DD));
				}else{
					obj.put("aftRegDt", aftVO.getRegDt());
				}
				//obj.put("aftRegDt", aftVO.getRegDt());
				obj.put("aftRegAddr", aftVO.getRegAddr());
				obj.put("aftCompTyp", aftVO.getCompTyp());
				obj.put("aftBizScope", aftVO.getBizScope());
				obj.put("aftSuppPrjTypCd", aftVO.getSuppPrjTypCd());
				obj.put("aftSucc", aftVO.getSucc());
				obj.put("crtTm", DateUtils.formatDateToString(lnkCompModDTO.getCrtTm(), DateUtils.YYYY_MM_DDHHMMSS));
				resultList.add(obj);
			}
		}
		pager.setResultList(resultList);
		return pager;
	}
}
